package com.chen.blue.converter.system;


import com.chen.blue.domain.dto.system.LogDto;

import com.chen.blue.domain.model.system.LogModel;

import com.chen.blue.domain.vo.excel.LogExcel;
import com.chen.blue.domain.vo.system.LogVo;
import org.springframework.cglib.beans.BeanCopier;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Created By CLT On 2023/10/28.
 */
@SuppressWarnings("all")
public abstract class LogConverter {


    private static final BeanCopier modelToVo = BeanCopier.create(LogModel.class, LogVo.class, false);
    private static final BeanCopier dtoToModel = BeanCopier.create(LogDto.class, LogModel.class, false);
    private static final BeanCopier voToExcel = BeanCopier.create(LogVo.class, LogExcel.class, false);
    private static final BeanCopier excelToModel = BeanCopier.create(LogExcel.class, LogModel.class, false);

    /**
     * model->vo
     *
     * @param model
     * @return
     */
    public static LogVo modelToVo(LogModel model) {
        if (Objects.isNull(model)) {
            return null;
        }
        LogVo logVo = new LogVo();
        modelToVo.copy(model, logVo, null);
        return logVo;
    }

    /**
     * dto->model
     *
     * @param dto
     * @return
     */
    public static LogModel dtoToModel(LogDto dto) {
        if (Objects.isNull(dto)) {
            return null;
        }
        LogModel logModel = new LogModel();
        dtoToModel.copy(dto, logModel, null);
        return logModel;
    }

    /**
     * model->volist
     *
     * @param modelList
     * @return
     */
    public static List<LogVo> modelToVoList(List<LogModel> modelList) {
        if (modelList.size() == 0) {
            return null;
        }
        List<LogVo> logVoList = new ArrayList<>();
        for (LogModel logModel : modelList) {
            logVoList.add(modelToVo(logModel));
        }
        return logVoList;
    }

    /**
     * vo->excel
     *
     * @param voList
     * @return
     */
    public static List<LogExcel> voToExcel(List<LogVo> voList) {
        if (voList.size() == 0) {
            return null;
        }
        List<LogExcel> logExcelList = new ArrayList<>();
        LogExcel logExcel = null;
        for (LogVo logVo : voList) {
            logExcel = new LogExcel();
            voToExcel.copy(logVo, logExcel, null);
            logExcelList.add(logExcel);
        }
        return logExcelList;
    }

    /**
     * excel->vo
     *
     * @param excelList
     * @return
     */
    public static List<LogModel> excelToDto(List<LogExcel> excelList) {
        if (excelList.size() == 0) {
            return null;
        }
        List<LogModel> logModelList = new ArrayList<>();
        LogModel logModel = null;
        for (LogExcel logExcel : excelList) {
            logModel = new LogModel();
            excelToModel.copy(logExcel, logModel, null);
            logModelList.add(logModel);
        }
        return logModelList;
    }


}
